package models;

import entities.Medium;
import javax.swing.AbstractListModel;
import javax.swing.DefaultListModel;
import javax.swing.JList;

/**
 *
 * @author Lucyia
 */
public class MediumList extends AbstractListModel<Medium> {
    private JList jList;
    private DefaultListModel jListModel = new DefaultListModel();
    
    public MediumList() {
        jList = new JList(jListModel);               
    }
    
    public void addMediumToJList(Medium medium) {        
        jListModel.addElement(medium);  
        int lastRow = jList.getModel().getSize();
        fireContentsChanged(jListModel, 0, lastRow);
    }
    
    public void clearJList() {
        jListModel = new DefaultListModel();
        jList = new JList(jListModel);       
    }
    
    @Override
    public int getSize() {
        return jList.getModel().getSize();
    }

    @Override
    public Medium getElementAt(int i) {
        return (Medium) jList.getModel().getElementAt(i);
    }
    
    
    
}
